﻿using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp;

namespace mozhi.smarterp.Finance.Files
{
    /// <summary>
    /// 附件
    /// </summary>
    public class Attachment : AggregateRootBase<Guid>
    {
        public string ModuleCode { private set; get; }

        /// <summary>
        /// 附件归属
        /// </summary>
        public Guid OwnerId { private set; get; }

        public string FileName {  private set; get; }

        public string FileExtension {  private set; get; }

        public Guid RemoteFileId { private set; get; }

        public string ContentType { private set; get; }

        private Attachment() { }


        public Attachment(Guid id , Guid owenrId , string moduleCode, string fileName, string fileExtension , string contentType, Guid remoteFileId)
        {
            Id = id;
            OwnerId = owenrId;
            ModuleCode = moduleCode;
            FileName = fileName;
            FileExtension = fileExtension;
            RemoteFileId = remoteFileId;
            ContentType = contentType;
            Validate();
        }


        #region
        private void Validate()
        {
            if (OwnerId == default)
                throw new BusinessException("100000", "OwnerId(附件拥有者)不能为空");

            if(ModuleCode.IsNullOrEmpty())
                throw new BusinessException("100000", "ModuleCode(附件模块)不能为空");

            if (RemoteFileId == default)
                throw new BusinessException("100000", "RemoteFileId(附件对应远程文件)不能为空");
        }
        #endregion
    }
}
